import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.swing.Timer;


public class GroupOfFireballs  implements ActionListener
{

	List<fireball> balls;
	Timer t;
	public GroupOfFireballs()
	{
		balls = new ArrayList<fireball>();
		t = new Timer(10, this);
		t.start();
	}



	public void paint(Graphics2D g)
	{
		if(balls != null)
		{
			for(fireball f : balls )
			{
				f.paint(g);    
			}
		}
	}
	public void addBall(fireball f)
	{
		t.addActionListener(f);
		balls.add(f);
	}
	
	public void deleteBall(fireball f)
	{
		t.removeActionListener(f);
		balls.remove(f);
	}



	@Override
	public void actionPerformed(ActionEvent e) {
		if(balls != null)
		{
			List<fireball> balls2 = new ArrayList<>();

			for(fireball f : balls)
			{

				if(f.getX() > 1275)
				{
					balls2.add(f);
					t.removeActionListener(f);
				}
			}
			balls.removeAll(balls2);
		}

	}
	
	public List<fireball> getFireballs()
	{
		return Collections.unmodifiableList(balls);
	}
}


//	
//
//
//	
